//
//  LongSearchBar.m
//  CoachsBook
//
//  Created by huiyong li on 2022/8/25.
//

#import "LongSearchBar.h"


@implementation LongSearchBar


- (instancetype)initWithType:(LongSearchBarType)Type WithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame])
    {
        [self SetUPUIWithType:Type];
        
    }
    return self;
}

-(void)SetUPUIWithType:(LongSearchBarType)Type
{
    
    if (Type == LongSearchBarExaminationRoom) {
        self.placeholder=@"请输入名字";
        //把边框颜色变为透明色
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:NSClassFromString(@"UIView")]&&view.subviews.count>0) {
                view.backgroundColor = [UIColor redColor];
                view.layer.cornerRadius=20;
                view.layer.masksToBounds=YES;
                break;
            }
        }
        //设置输入框的背景颜色
        UIView *searchTextField = [[[self.subviews firstObject] subviews] lastObject];
        searchTextField.subviews[0].backgroundColor = [UIColor clearColor];
        searchTextField.backgroundColor=rgba(246, 247, 252, 1);
        searchTextField.layer.cornerRadius=14;
        searchTextField.layer.masksToBounds=YES;
    }
    else
    {
        [self setBackgroundImage:[UIImage new]];
        self.placeholder=@"请输入服务关键词";
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:NSClassFromString(@"UIView")]&&view.subviews.count>0) {
                view.backgroundColor = rgba(245, 245, 250, 1);
                view.layer.cornerRadius=20;
                view.layer.masksToBounds=YES;
                
                break;
            }
        }
        //设置输入框的背景颜色
        UIView *searchTextField = [[[self.subviews firstObject] subviews] lastObject];
        searchTextField.subviews[0].backgroundColor = rgba(245, 245, 250, 1);
        searchTextField.backgroundColor=[UIColor clearColor];
        searchTextField.layer.cornerRadius=14;
        searchTextField.layer.masksToBounds=YES;
    }

    
}



-(void)layoutSubviews
{
    [super layoutSubviews];
//    UIView *searchTextField = [[[self.subviews firstObject] subviews] lastObject];
    
    //因为样式都一定 所以定死大小和上下左右距离 可通过设置contentInset 来改变
//    if (!self.contentInset.left)
//    {
//        searchTextField.frame=CGRectMake(10, 0, self.frame.size.width-20, self.frame.size.height);
//
//    }
//    //设置了contentInset的情况
//    else
//    {
//         searchTextField.frame=CGRectMake(self.contentInset.left, self.contentInset.top, self.frame.size.width-self.contentInset.left-self.contentInset.right , self.frame.size.height-self.contentInset.top-self.contentInset.bottom);
//    }
    
    
}

//xib里面的实现
-(void)awakeFromNib
{
    [super awakeFromNib];
}



@end
